package com.cskaoyan.service;


import com.cskaoyan.bean.marketBean.MarketSystem;
import com.cskaoyan.bean.marketBean.MarketSystemExample;
import com.cskaoyan.bean.vo.zxw.MarketExpressConfigVo;
import com.cskaoyan.bean.vo.zxw.MarketMallConfigVo;
import com.cskaoyan.bean.vo.zxw.MarketOrderConfigVo;
import com.cskaoyan.bean.vo.zxw.MarketWxConfigVo;
import com.cskaoyan.mapper.marketMapper.MarketSystemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 曾添乐啦
 * @since 2022/12/29 15:21
 */
@Service
public class AdminConfigServiceImpl implements AdminConfigService {


    @Autowired
    MarketSystemMapper marketSystemMapper;

    /**
     * 响应参数
     * market_mall_address: "test-demo1"
     * market_mall_latitude: "31.201900"
     * market_mall_longitude: "888"
     * market_mall_name: "商场配置test"
     * market_mall_phone: "19900092220"
     * market_mall_qq: "12312312@qq.com"
     *
     * @return
     */
    //查询商场配置信息
    @Override
    public MarketMallConfigVo findmallConfig() {
        //查询
        MarketSystemExample example = new MarketSystemExample();
        //拼接查询条件，通过响应参数,可以知道查的表中元素都含有mall
        MarketSystemExample.Criteria criteria = example.createCriteria();
        criteria.andKeyNameLike("%" + "mall" + "%");

        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(example);

        MarketMallConfigVo mallConfig = new MarketMallConfigVo();

        //TODO:为什么用if逻辑判断赋不上值，封装返回结果
       /* for (MarketSystem marketSystem : marketSystems) {
            if (marketSystem.getKeyName() == "market_mall_address") {
//                String value1= marketSystem.getKeyValue();
//                mallConfig.setMarket_mall_address(value1);
                mallConfig.setMarket_mall_address(marketSystem.getKeyValue());
            }
            if (marketSystem.getKeyName() == "market_mall_latitude") {
                mallConfig.setMarket_mall_latitude(marketSystem.getKeyValue());
            }
            if (marketSystem.getKeyName() == "market_mall_longitude") {
                mallConfig.setMarket_mall_longitude(marketSystem.getKeyValue());
            }
            if (marketSystem.getKeyName() == "market_mall_name") {
                mallConfig.setMarket_mall_name(marketSystem.getKeyValue());
            }
            if (marketSystem.getKeyName() == "market_mall_phone") {
                mallConfig.setMarket_mall_phone(marketSystem.getKeyValue());
            }
            if (marketSystem.getKeyName() == "market_mall_qq") {
                mallConfig.setMarket_mall_qq(marketSystem.getKeyValue());
            }
        }
*/
        //封装返回结果
        for (MarketSystem marketSystem : marketSystems) {
            switch (marketSystem.getKeyName()) {
                case "market_mall_address":
                    mallConfig.setMarket_mall_address(marketSystem.getKeyValue());
                    break;
                case "market_mall_latitude":
                    mallConfig.setMarket_mall_latitude(marketSystem.getKeyValue());
                    break;
                case "market_mall_longitude":
                    mallConfig.setMarket_mall_longitude(marketSystem.getKeyValue());
                    break;
                case "market_mall_name":
                    mallConfig.setMarket_mall_name(marketSystem.getKeyValue());
                    break;
                case "market_mall_phone":
                    mallConfig.setMarket_mall_phone(marketSystem.getKeyValue());
                    break;
                case "market_mall_qq":
                    mallConfig.setMarket_mall_qq(marketSystem.getKeyValue());
                    break;
            }
        }
        return mallConfig;
    }

    /**
     * 响应参数
     * market_express_freight_min: "100"
     * market_express_freight_value: "6"
     *
     * @return
     */
    //查询运费信息
    @Override
    public MarketExpressConfigVo findexpressConfig() {

        //查询
        MarketSystemExample example = new MarketSystemExample();
        //拼接查询条件，通过响应参数可知查的表元素都含express
        MarketSystemExample.Criteria criteria = example.createCriteria();
        criteria.andKeyNameLike("%" + "express" + "%");

        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(example);

        MarketExpressConfigVo marketExpressVo = new MarketExpressConfigVo();

        //封装返回结果
        for (MarketSystem marketSystem : marketSystems) {
            switch (marketSystem.getKeyName()) {
                case "market_express_freight_min":
                    marketExpressVo.setMarket_express_freight_min(marketSystem.getKeyValue());
                    break;
                case "market_express_freight_value":
                    marketExpressVo.setMarket_express_freight_value(marketSystem.getKeyValue());
                    break;
            }
        }
        return marketExpressVo;
    }

    /**
     * 响应参数
     * market_order_comment: "2"
     * market_order_unconfirm: "5"
     * market_order_unpaid: "301q"
     *
     * @return
     */
    //查询订单配置信息
    @Override
    public MarketOrderConfigVo findorderConfig() {

        //查询
        MarketSystemExample example = new MarketSystemExample();
        //拼接查询条件，通过响应参数可知查的表元素都含order
        MarketSystemExample.Criteria criteria = example.createCriteria();
        criteria.andKeyNameLike("%" + "order" + "%");

        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(example);

        MarketOrderConfigVo marketOrderConfigVo = new MarketOrderConfigVo();

        //封装返回结果
        for (MarketSystem marketSystem : marketSystems) {
            switch (marketSystem.getKeyName()) {
                case "market_order_comment":
                    marketOrderConfigVo.setMarket_order_comment(marketSystem.getKeyValue());
                    break;
                case "market_order_unconfirm":
                    marketOrderConfigVo.setMarket_order_unconfirm(marketSystem.getKeyValue());
                    break;
                case "market_order_unpaid":
                    marketOrderConfigVo.setMarket_order_unpaid(marketSystem.getKeyValue());
                    break;
            }
        }
        return marketOrderConfigVo;
    }

    /**
     * 响应参数
     * market_wx_catlog_goods: "3"
     * market_wx_catlog_list: "2"
     * market_wx_index_brand: "4"
     * market_wx_index_hot: "6"
     * market_wx_index_new: "23"
     * market_wx_index_topic: "1"
     * market_wx_share: "true"
     * @return
     */
    //查询微信小程序配置信息
    @Override
    public MarketWxConfigVo findwxConfig() {
        //查询
        MarketSystemExample example = new MarketSystemExample();
        //拼接查询条件，通过响应参数可知查的表元素都含order
        MarketSystemExample.Criteria criteria = example.createCriteria();
        criteria.andKeyNameLike("%" + "wx" + "%");

        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(example);

        MarketWxConfigVo marketWxConfigVo = new MarketWxConfigVo();

        //封装返回结果
        for (MarketSystem marketSystem : marketSystems) {
            switch (marketSystem.getKeyName()) {
                case "market_wx_catlog_goods":
                    marketWxConfigVo.setMarket_wx_catlog_goods(marketSystem.getKeyValue());
                    break;
                case "market_wx_catlog_list":
                    marketWxConfigVo.setMarket_wx_catlog_list(marketSystem.getKeyValue());
                    break;
                case "market_wx_index_brand":
                    marketWxConfigVo.setMarket_wx_index_brand(marketSystem.getKeyValue());
                    break;
                case "market_wx_index_hot":
                    marketWxConfigVo.setMarket_wx_index_hot(marketSystem.getKeyValue());
                    break;
                case "market_wx_index_new":
                    marketWxConfigVo.setMarket_wx_index_new(marketSystem.getKeyValue());
                    break;
                case "market_wx_index_topic":
                    marketWxConfigVo.setMarket_wx_index_topic(marketSystem.getKeyValue());
                    break;
                case "market_wx_share":
                    marketWxConfigVo.setMarket_wx_share(marketSystem.getKeyValue());
                    break;
            }
        }
        return marketWxConfigVo;
    }


}
